package cn.hongxin.sap.conn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author hengji.li@getech.cn
 * @date 2020/2/19
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
    /**
     * 对所有api扫描配置:controller路径
     */
    private static final String BASE_PACKAGE = "cn.hongxin.sap.conn";

    /**
     * 版本
     */
    private static final String API_VERSION = "1.0-SNAPSHOT";

    /**
     * Swagger2的配置文件：内容、扫描包等
     *
     * @return the docket
     */
    @Bean
    public Docket createApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建api文档的详细方法
     *
     * @return ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("archetype Swagger2 Api")
                .version(API_VERSION)
                //描述
                .description("archetype API 描述")
                .build();
    }
}
